package jinzhi_turn_liwenshuai;
//编码：软工2413班李文帅
//导入List用于存放商
//目前仅支持16以下所有进制，如3进制，9进制，16进制
import java.util.ArrayList;
import java.util.List;
//import java.util.Scanner;

public class shuTurn {
    private int x;
    private int type;
    private List<Integer> list=new ArrayList<>();

    public shuTurn(int x, int type)  throws IllegalArgumentException{
        if (type > 16) {
            throw new IllegalArgumentException("进制必须在16之内（包含16）");
        }
        this.x = x;
        this.type = type;
    }

    public void turn_16() {

        if (x == 0) {
            System.out.println("0");
            return;
        } else if (type==1) {
            for (int i = 1; i <= x; i++) {
                System.out.print(1);
            }
        } else {
            char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7',
                    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

            int shang = x;
            int yushu;

            while (shang != 0) {
                yushu = shang %type;
                list.add(yushu);
                shang = shang / type;
            }

            for (int i = list.size() - 1; i >= 0; i--) {
                System.out.print(hexChars[list.get(i)]);
            }
        }

        System.out.println();
    }
}

